package com.bd.scm.module.synchronization.service.impl;

import com.bd.scm.dao.mapper.synchronization.SynchronizationMapper;
import com.bd.scm.domain.dto.synchronization.SynchronizationDto;
import com.bd.scm.domain.models.synchronization.BdVisitorItems;
import com.bd.scm.domain.models.synchronization.DtAllcarsq;
import com.bd.scm.domain.models.synchronization.SmartCarhj;
import com.bd.scm.domain.models.synchronization.SmartCartemp;
import com.bd.scm.module.synchronization.service.SynchronizationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class SynchronizationServiceImpl implements SynchronizationService {

    @Resource
    private SynchronizationMapper synchronizationMapper;

    /**
     * 1.同步车辆合计数
     * @param smartCarhjList 车辆合计数据集合
     */
    @Override
    public void disposeSmartCarhj(List<SmartCarhj> smartCarhjList) {
        if(smartCarhjList.size()>0){
            for (SmartCarhj smartCarhj : smartCarhjList) {
                //1.1是否存在
                int smartCarhjCount = this.synchronizationMapper.getSmartCarhjCount(smartCarhj);
                if(smartCarhjCount>0){
                    //1.2存在根据名称修改
                    this.synchronizationMapper.updateSmartCarhj(smartCarhj);
                }else{
                    //1.3不存在添加
                    this.synchronizationMapper.insertSmartCarhj(smartCarhj);
                }
            }
        }
    }

    /**
     * 2.同步车辆进出记录
     * @param smartCartempList 车辆进出记录数据集合
     */
    @Override
    public void disposeSmartCartemp(List<SmartCartemp> smartCartempList) {
        if(smartCartempList.size()>0){
            for (SmartCartemp smartCartemp : smartCartempList) {
                //2.1是否存在
                int smartCartempCount = this.synchronizationMapper.getSmartCartempCount(smartCartemp);
                if(smartCartempCount>0){
                    //2.2存在根据ID修改
                    this.synchronizationMapper.updateSmartCartemp(smartCartemp);
                }else{
                    //2.3不存在添加
                    this.synchronizationMapper.insertSmartCartemp(smartCartemp);
                }
            }
        }
    }

    /**
     * 3.同步访客进出记录
     * @param bdVisitorItemsList 访客进出记录数据集合
     */
    @Override
    public void disposeBdVisitorItems(List<BdVisitorItems> bdVisitorItemsList) {
        if(bdVisitorItemsList.size()>0){
            for (BdVisitorItems bdVisitorItems : bdVisitorItemsList) {
                //3.1是否存在
                int bdVisitorItemsCount = this.synchronizationMapper.getBdVisitorItemsCount(bdVisitorItems);
                if(bdVisitorItemsCount>0){
                    //3.2存在根据ID修改
                    this.synchronizationMapper.updateBdVisitorItems(bdVisitorItems);
                }else{
                    //3.3不存在添加
                    this.synchronizationMapper.insertBdVisitorItems(bdVisitorItems);
                }
            }
        }
    }

    /**
     * 4.同步车辆权限信息
     * 根据开始日期 结束日期查询车辆权限表
     * @param syncDto
     * @return
     */
    @Override
    public List<DtAllcarsq> getDtAllcarsqList(SynchronizationDto syncDto) {
        return this.synchronizationMapper.getDtAllcarsqList(syncDto);
    }

}
